package com.itheima.info.manager.dao;

import com.itheima.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teas = new Teacher[5];

    public boolean addTeacher(Teacher tea) {
        int index = -1;
        for (int i = 0; i < teas.length; i++) {
            Teacher t = teas[i];
            if (t == null) {
                index = i;
                break;
            }
        }

        if (index==-1){
            return false;
        }else{
            teas[index]=tea;
            return true;
        }
    }


    public Teacher[] findAllTeacher() {
        return teas;
    }

    public void deleteTeacherById(String teaId) {
        int index = getIndex(teaId);
        teas[index] = null;
    }

    private int getIndex(String teaId) {
        int index = -1;
        for (int i = 0; i < teas.length; i++) {
            Teacher stu = teas[i];
            if(stu != null && stu.getId().equals(teaId)){
                index = i;
                break;
            }
        }
        return index;
    }

    public void updateTeacher(String updateId, Teacher newTea) {
        int index = getIndex(updateId);
        teas[index] = newTea;
    }
}
